const http=require('http');
const fs=require('fs');
const path=require('path');
http.createServer((req,res)=>{
    var arr=[];
    var is=false;
    var filePath=path.join(__dirname,"/data.json");
    var fileContent=fs.readFileSync(filePath);
    var fileString=fileContent.toString();
    var fileObj=JSON.parse(fileString);
    for(var i in fileObj.userList){
        arr.push(fileObj.userList[i]);
    }
    var str="";
    req.on("data",(chunk)=>{
        str+=chunk;
    })
    req.on("end",()=>{
        var obj=JSON.parse(str);
        for(var i=0;i<arr.length;i++){
            if(arr[i].userName==obj.userName && arr[i].pwd==obj.pwd){
                is=true;
            }
        }
        if(is==true){
            console.log("登陆成功");
        }else{
            console.log("用户名、密码错误");
        }
    })
}).listen(8081);